nice_things/fs/read_link.sh
read_link
Since 0.3.0 · Source
import "{ read_link }" from nice_things/fs/read_link.sh
Synopsisread_link <out_var> <file>
Configuration
–
Description
Get value of a symbolic link.
Note
This is not a pure sh implementation because it depends on the external
lsutility to read the target of the symlink. This works consistently because the output oflsis strictly specified in POSIX, but it means this function can be slower than most other functions in the framework.
Options
–
Operands
<out_var>: Output variable; the result will be written to this variable.<file>: Path to a symbolic link.
Stdin
–
Stdout
–
Stderr
–
Exit status
0: Successful completion.22:<file>is not a symbolic link.123: Unexpected error.
Abort
–
Usage examples
# Read the value of a link
link=/path/to/link
read_link link_target "$link" || {
case $? in
22) log_error "File is not a symbolic link: '${link}'" ;;
*) log_error "Unexpected error trying to read link at '${link}'" ;;
esac
}